package com.ws.common.util;


import org.springframework.util.StringUtils;

import java.math.BigDecimal;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;


/**
 * 
 * 功能描述:日期相关的工具类
 */
public class DateUtils {

	public static final String SIMPLE_DATE_STR = "yyyy-MM-dd";
	public static final String FULL_DATE_STR = "yyyy-MM-dd HH:mm:ss";
	public static final String PART_DATE_STR = "yyyy-MM-dd HH:mm";
	
	public static final String SIMPLE_RULE_DATE_STR = "yyyy/MM/dd";
	public static final String FULL_RULE_DATE_STR = "yyyy/MM/dd HH:mm:ss";
	public static final String PART_RULE_DATE_STR = "yyyy/MM/dd HH:mm";
	public static final String SMALL_PART_RULE_DATE_STR = "HH:mm";
	
	public static final String DATE_FORMAT_YYYYMMDDHHMMSS = "yyyyMMddHHmmss";
	
	public static final String DATE_FORMAT_YYYYMMDD="yyyyMMdd";
	public static final String DATE_FORMAT_YYYYMMDDHHMM="yyyyMMddHHmm";
	
	
	public static Date now(){
		return new Date();
	}
	
	
	/**
	 * 
	 * 功能描述：根据指定格式解析日期格式
	 *@param dateStr
	 *@param formatStr
	 *@return
	 *@throws ParseException
	 */
	public static Date parseToFormatDate(String dateStr,String formatStr) throws ParseException{
		if(StringUtils.isEmpty(dateStr)||StringUtils.isEmpty(formatStr)){
    		return null;
    	}
		DateFormat dateFormat = new SimpleDateFormat(formatStr);
		return dateFormat.parse(dateStr);
	}
	
	/**
	 * 
	 * 功能描述:日期类型转换字符串
	 * @param date
	 * @param fmt
	 * @return
	 * @throws ParseException
	 */
	public static String parseToFormatString(Date date, String fmt) throws ParseException {
		SimpleDateFormat sdf = new SimpleDateFormat(fmt);
		String dateStr = sdf.format(date);
		return dateStr;
	}
	


	/**
	 * 
	 * 功能描述:判断一个日期是否就是当前日期
	 * @param compareDate
	 *            需要判断的日期
	 * @return 是否是当前日期
	 */
	public static boolean isDateToday(Date compareDate) {
		if (compareDate == null){
			throw new IllegalArgumentException("date should not be null");
		}
		DateFormat dateFormat = new SimpleDateFormat(SIMPLE_DATE_STR);
		String dateStr = dateFormat.format(compareDate);
		Date today = new Date();
		String todayStr = dateFormat.format(today);
		return todayStr.equals(dateStr);
	}

	/**
	 * 
	 * 功能描述:判断两个日期是否是同一天

	 * @param date1
	 *            待判断日期一
	 * @param date2
	 *            待判断日期二
	 * @return 是否是同一天
	 */
	public static boolean isSameDate(Date date1, Date date2) {
		if (date1 == null || date2 == null){
			throw new IllegalArgumentException("date should not be null");
		}
		DateFormat dateFormat = new SimpleDateFormat(SIMPLE_DATE_STR);
		String dateStr1 = dateFormat.format(date1);
		String dateStr2 = dateFormat.format(date2);
		return dateStr1.equals(dateStr2);
	}

	/**
	 * 
	 * 功能描述:在startDate上加上dayNum天，dayNum可以是负数，如果是负数相当于减dayNum天

	 * @param startDate
	 *            待操作的日期
	 * @param dayNum
	 *            加上的天数
	 * @return
	 */
	public static Date addDate(Date startDate, int dayNum) {
		if (startDate == null) {
			return null;
		}
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(startDate);
		calendar.add(Calendar.DATE, dayNum);
		return calendar.getTime();
	}
	
	/**
	 * 功能描述：在startDate上加上monthNum月，monthNum可以是负数，如果是负数相当于减monthNum月
	 * @param startDate 待操作的日期
	 * @param monthNum 加上的月天数
	 * @return
	 */
	public static Date addMonth(Date startDate, int monthNum) {
		if (startDate == null) {
			return null;
		}
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(startDate);
		calendar.add(Calendar.MONTH, monthNum);
		return calendar.getTime();
	}
	
	/**
	 * 
	 * 功能描述:在startDate上加上hourNum小时，hourNum可以是负数，如果是负数相当于减hourNum小时
	 * 
	 * @param startDate
	 *            待操作的日期
	 *            加上的小时
	 * @return
	 */
	public static Date addHour(Date startDate, int hourNum) {
		if (startDate == null) {
			return null;
		}
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(startDate);
		calendar.add(Calendar.HOUR, hourNum);
		return calendar.getTime();
	}

	/**
	 * 
	 * 功能描述:将日期date进行格式化
	 * @param date
	 *            待格式化的日期
	 * @param formatStr
	 *            格式化字符串
	 * @return 格式化之后的日期字符串
	 */
	public static String dateFormat(Date date, String formatStr) {
		if (date == null || formatStr == null) {
			throw new IllegalArgumentException(
					"the date or formatStr should not be null");
		}
		DateFormat dateFormat = new SimpleDateFormat(formatStr);
		return dateFormat.format(date);
	}

	/**
	 * 
	 * 功能描述:获取两个日期的相差天数，不够一天算0天。例如2013-06-19 00:00:00与2013-06-21 23:59:59是相差2天
	 * @param startDay
	 *            开始日期
	 * @param endDay
	 *            结束日期
	 * @return 相差的天数
	 */
	public static int getBetweenFloorDays(Date startDay, Date endDay) {
        long diff = endDay.getTime() - startDay.getTime();
        long betweenDays = diff / (1000L * 24 * 60 * 60);
        return (int) betweenDays;
    }

    /**
     * 
     * 功能描述:获取两个日期的相差小时数，四舍五入取相隔天数。
     * @param startDay
     *            开始日期
     * @param endDay
     *            结束日期
     * @return 相差的小时数
     */
    public static int getBetweenRoundDays(Date startDay, Date endDay) {
    	long diff = endDay.getTime() - startDay.getTime();
        float betweenDays = (float) (diff / (1000L * 24 * 60 * 60.0));
	    return Math.round(betweenDays);
    }
    
	/**
     * 
     * 功能描述:获取两个日期的相差小时数，不够一小时算0小时。
     * @param startDay
     *            开始日期
     * @param endDay
     *            结束日期
     * @return 相差的小时数
     */
    public static int getBetweenFloorHours(Date startDay, Date endDay) {
	    if (startDay == null || endDay == null) {
	        throw new IllegalArgumentException(
	                    "startDay or endDay or dateFormat should not be null");
	    }
	    long diff = endDay.getTime() - startDay.getTime();
	    long betweenDays =   diff / (1000 * 60 * 60);
	    return (int)betweenDays;

    }
        
    /**
     * 功能描述:获取两个日期的除去天后相差的小时数
     * @param startDay
     * @param endDay
     * @return
     * @throws ParseException 
     */
    public static int getBetweenFloorHoursResidue(String startDay, String endDay, String dateFormatStr) throws ParseException {
    	if (startDay == null || endDay == null || dateFormatStr == null) {
			throw new IllegalArgumentException(
					"startDay or endDay or dateFormat should not be null");
		}
    	DateFormat dateFormat = new SimpleDateFormat(dateFormatStr);
    	int day = getBetweenFloorDays(dateFormat.parse(startDay), dateFormat.parse(endDay));
        long diff = dateFormat.parse(endDay).getTime() - dateFormat.parse(startDay).getTime() - (day * 24 * 60 * 60 * 1000l);
        long betweenDays = diff / (1000L * 60 * 60);
        return (int) betweenDays;
    }
    
    /**
     * 功能描述：获取两个日期的时间间隔，单位是小时，保留一位小数
     * @param startDay 开始时间
     * @param endDay 结束时间
     * @param dateFormatStr 格式化
     * @return
     */
    public static double getBetweenDoubleHours(String startDay, String endDay, String dateFormatStr) throws ParseException {
    	if (startDay == null || endDay == null || dateFormatStr == null) {
			throw new IllegalArgumentException(
					"startDay or endDay or dateFormat should not be null");
		}
    	DateFormat dateFormat = new SimpleDateFormat(dateFormatStr);
    	DecimalFormat df = new DecimalFormat("0.0");
    	long diff = dateFormat.parse(endDay).getTime() - dateFormat.parse(startDay).getTime();
    	String betweenHours = df.format((double) diff / (1000 * 60 * 60));
    	return Double.valueOf(betweenHours);
    }
    
    /**
     * 功能描述：30 - 获取两个日期的时间间隔，单位是小时，保留一位小数
     * @param startDay 开始时间
     * @param endDay 结束时间
     * @param dateFormatStr 格式化
     * @return
     */
    public static double getBetweenDoubleHoursReverse(String startDay, String endDay, String dateFormatStr) throws ParseException {
    	if (startDay == null || endDay == null || dateFormatStr == null) {
			throw new IllegalArgumentException(
					"startDay or endDay or dateFormat should not be null");
		}
    	DecimalFormat df = new DecimalFormat("0.0");
    	double doubleHours = getBetweenDoubleHours(startDay, endDay, dateFormatStr);
    	String timeFormat = df.format(30.0 * 24 - doubleHours); // 30天*24小时
    	return Double.valueOf(timeFormat);
    }

	/**
	 * 
	 * 功能描述:获取两个日期的相差天数，不够一天算0天。例如2013-06-19 00:00:00与2013-06-21 23:59:59是相差2天
	 * @param startDay
	 *            开始日期
	 * @param endDay
	 *            结束日期
	 * @param dateFormatStr
	 *            日期格式
	 * @return 相差的天数
	 * @throws ParseException
	 */
	public static int getBetweenFloorDays(String startDay, String endDay,
			String dateFormatStr) throws ParseException {
		if (startDay == null || endDay == null || dateFormatStr == null) {
			throw new IllegalArgumentException(
					"startDay or endDay or dateFormat should not be null");
		}
		DateFormat dateFormat = new SimpleDateFormat(dateFormatStr);
		int betweenDays = getBetweenFloorDays(dateFormat.parse(startDay),
				dateFormat.parse(endDay));
		return betweenDays;
	}

	/**
	 * 
	 * 功能描述:获取当前的时间，时间格式由入参指定
	 *
	 * @param dateFormatStr
	 *            时间格式
	 * @return 格式化后的当前时间
	 */
	public static String getCurrentTimeStr(String dateFormatStr) {
		Date currentTime = new Date();
		DateFormat dateFormat = new SimpleDateFormat(dateFormatStr);
		return dateFormat.format(currentTime);
	}

	/**
	 * 
	 * 功能描述:获取指定日期的年月日中文描述
	 * @param date
	 *            指定日期
	 * @return 年月日中文描述
	 */
	public static String getChineseDate(Date date) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		int year = calendar.get(Calendar.YEAR);
		int month = calendar.get(Calendar.MONDAY) + 1;
		int day = calendar.get(Calendar.DAY_OF_MONTH);
		return year + "年" + month + "月" + day + "日";
	}

	/**
	 * 
	 * 功能描述：计算相隔天数
	 * @param d1
	 * @param d2
	 * @return
	 */
	public static int getDaysBetween(Calendar d1, Calendar d2) {
		if (d1.after(d2)) {
			Calendar swap = d1;
			d1 = d2;
			d2 = swap;
		}
		int days = d2.get(Calendar.DAY_OF_YEAR) - d1.get(Calendar.DAY_OF_YEAR);
		int y2 = d2.get(Calendar.YEAR);
		if (d1.get(Calendar.YEAR) != y2) {
			d1 = (Calendar) d1.clone();
			do {
				days += d1.getActualMaximum(Calendar.DAY_OF_YEAR);
				d1.add(Calendar.YEAR, 1);
			} while (d1.get(Calendar.YEAR) != y2);
		}
		return days;
	}

	/**
	 *
	 * 功能描述：计算相隔天数
	 * @param d1
	 * @param d2
	 * @return
	 */
	public static int getDaysBetween(Date d1, Date d2) {
		Calendar cal1 = Calendar.getInstance();
		Calendar cal2 = Calendar.getInstance();
		cal1.setTime(d1);
		cal2.setTime(d2);
		int days = getDaysBetween(cal1, cal2);
		return days;
	}

	/**
	 *
	 * 功能描述：计算相隔月份数
	 *
	 * @param date1
	 * @param date2
	 * @return
	 */
	public static int getMonthsBetween(Date date1, Date date2) {

		Calendar c1 = Calendar.getInstance();
		Calendar c2 = Calendar.getInstance();
		c1.setTime(date1);
		c2.setTime(date2);

		int year1 = c1.get(Calendar.YEAR);
		int year2 = c2.get(Calendar.YEAR);
		int month1 = c1.get(Calendar.MONTH);
		int month2 = c2.get(Calendar.MONTH);
		int d1 = c1.get(Calendar.DATE);
		int d2 = c2.get(Calendar.DATE);

		if (d2 < d1) {
			return (year2 - year1) * 12 + month2 - month1 - 1;
		} else {
			return (year2 - year1) * 12 + month2 - month1;
		}

	}

	/**
	 * 功能描述：计算相隔年份数
	 * @param date1
	 * @param date2
	 * @return
	 */
	public static int getYearBetween(Date date1, Date date2) {
		int monthsBetween = getMonthsBetween(date1, date2);
		return monthsBetween / 12;
	}

	/**
	 * 功能描述：获取日期间的间隔 XX天XX小时XX分
	 * @return
	 */
	public static String getTimeBetweenDate(String startTime, String endTime) {
		try {
			if (startTime == null || endTime == null){
				return "";
			}else {
				java.sql.Timestamp start = java.sql.Timestamp
						.valueOf(startTime);
				java.sql.Timestamp end = java.sql.Timestamp.valueOf(endTime);
				long betweenHours = (end.getTime() - start.getTime()) / 1000;
				if (betweenHours < 0){
					return "";
				}else{

					return calcdhm(betweenHours);
				}
			}
		} catch (Exception e) {
			return "";
		}
	}

	/**
	 *
	 * 功能描述：将时间的长整型转换为天、小时、分
	 * @param timeinseconds
	 * @return
	 */
	public static String calcdhm(long timeinseconds) {
		String dhm = "";
		long days = timeinseconds / (24 * 3600);
		long hours = timeinseconds % (24 * 3600) / 3600;
		long minutes = timeinseconds % 3600 / 60;
		if (days + hours + minutes == 0) {
			dhm = "小于1分钟";
		}
		if (days + hours == 0 && days + hours + minutes != 0){
			dhm = minutes + "分钟";
		}
		if (days == 0 && days + hours != 0){
			dhm = hours + "小时" + minutes + "分钟";
		}
		if (days != 0){
			dhm = days + "天" + hours + "小时" + minutes + "分钟";
		}
		return dhm;
	}

	/**
	 * 功能描述：将日期长整型转换成String格式
	 * @param currentTime
	 * @return
	 */
	public static String conversionLongToStr(Object currentTime) {
		if (currentTime == null || currentTime instanceof String) {
			return (String)currentTime;
		}
		SimpleDateFormat dateFormat = new SimpleDateFormat(FULL_DATE_STR);
		return dateFormat.format(currentTime);
	}


	/**
	 * 功能描述：返回最大的日期
	 * @param date1
	 * @param date2
	 * @return
	 */
	public static Date getMaxDate(Date date1,Date date2) {
	    if(date1 == null && date2 == null){
	        return null;
	    }else if(date1 == null){
	        return date2;
	    }else if(date2 == null){
	        return date1;
	    }else{
	        long time1 = date1.getTime();
	        long time2 = date2.getTime();
	        return time1 > time2 ? date1:date2;
	    }
	}

	/**
	 *
	 * 功能描述：返回当前时间是星期几
	 *@param date
	 *@return
	 */
	public static int getWeek(Date date) {
	  Calendar c = Calendar.getInstance();
	  c.setTime(date);
	   int hour=c.get(Calendar.DAY_OF_WEEK);
	  // hour中存的就是星期几了，其范围 0~6
	  // 0=星期日 7=星期六，其他类推
	  return hour - 1;
	 }

	/**
	 * 功能描述：获取上一季度起始时间
	 * @param date
	 * @return
	 */
	public static Date getPrevSeasonBegin(Date date) {
		Calendar c = Calendar.getInstance();
        c.setTime(date);
		// 当前季度
        int season = getSeason(date);
        int year = 0;
        int month = 0;
        int day = 0;
        year = c.get(Calendar.YEAR);
		// 如果是一季度，则获取去年
        if (1 == season) {
        	year = c.get(Calendar.YEAR) - 1;
        	month = Calendar.OCTOBER;
		} else if (2 == season) {
        	month = Calendar.JANUARY;
		} else if (3 == season) {
        	month = Calendar.APRIL;
		} else if (4 == season) {
        	month = Calendar.JULY;
		}
        day = c.getActualMinimum(Calendar.DAY_OF_MONTH);
        c.set(year, month, day, 0, 0, 0);
        return c.getTime();
	}

	/**
	 * 功能描述：获取上一季度结束时间
	 * @param date
	 * @return
	 */
	public static Date getPrevSeasonEnd(Date date) {
		Calendar c = Calendar.getInstance();
        c.setTime(date);
        int season = getSeason(date); // 当前季度
        int year = 0;
        int month = 0;
        int day = 0;
        year = c.get(Calendar.YEAR);
        if (1 == season) { // 如果是一季度，则获取去年
        	year = c.get(Calendar.YEAR) - 1;
        	month = Calendar.DECEMBER;
		} else if (2 == season) {
        	month = Calendar.MARCH;
		} else if (3 == season) {
        	month = Calendar.JUNE;
		} else if (4 == season) {
        	month = Calendar.SEPTEMBER;
		}
        c.set(Calendar.YEAR, year);
        c.set(Calendar.MONTH, month);
        day = c.getActualMaximum(Calendar.DAY_OF_MONTH);
        c.set(Calendar.DAY_OF_MONTH, day);
        c.set(year, month, day, 23, 59, 59);
        return c.getTime();
	}

	/**
	 * 功能描述：获得当前季度
	 * @param date
	 * @return
	 */
	public static int getSeason(Date date) {
		int season = 0;
		Calendar c = Calendar.getInstance();
		c.setTime(date);
		int month = c.get(Calendar.MONTH);
		switch (month) {
		case Calendar.JANUARY:
		case Calendar.FEBRUARY:
		case Calendar.MARCH:
			season = 1;
			break;
		case Calendar.APRIL:
		case Calendar.MAY:
		case Calendar.JUNE:
			season = 2;
			break;
		case Calendar.JULY:
		case Calendar.AUGUST:
		case Calendar.SEPTEMBER:
			season = 3;
			break;
		case Calendar.OCTOBER:
		case Calendar.NOVEMBER:
		case Calendar.DECEMBER:
			season = 4;
			break;
		default:
			break;
		}
		return season;
	}

	/**
	 * 功能描述：获取起始时间-当前时间间的数据
	 * 格式：["201506","201507","201508"]
	 * @param dateList
	 * @param startDateStr
	 * @return
	 * @throws ParseException
	 */
	public static List<String> getPeriodDate(List<String> dateList, String startDateStr) throws ParseException {
		String dateFormatStr = "yyyyMM";
		SimpleDateFormat sf = new SimpleDateFormat(dateFormatStr);
		String endDateStr = getCurrentTimeStr(dateFormatStr);

		Date startDate = sf.parse(startDateStr);
		Date endDate = sf.parse(endDateStr);
		dateList.add(startDateStr);
		if (startDate.before(endDate)) {
			Calendar calender = Calendar.getInstance();
			calender.setTime(startDate);
			calender.add(Calendar.MONTH, 1);
			String nextDateStr = sf.format(calender.getTime());
			getPeriodDate(dateList, nextDateStr);
		}
		return dateList;
	}

	/**
	 * 功能描述：校验字符串的日期格式
	 * @param dateStr
	 * @param formatStr
	 * @return
	 */
	public static boolean isValidDate(String dateStr, String formatStr) {
		if (StringUtils.isEmpty(dateStr) || StringUtils.isEmpty(formatStr)) {
			return false;
		}
		boolean convertSuccess = true;
		// 指定日期格式为四位年/两位月份/两位日期，注意yyyy/MM/dd区分大小写；
		SimpleDateFormat format = new SimpleDateFormat(formatStr);
		try {
			// 设置lenient为false.
			// 否则SimpleDateFormat会比较宽松地验证日期，比如2007/02/29会被接受，并转换成2007/03/01
			format.setLenient(false);
			format.parse(dateStr);
		} catch (ParseException e) {
			// 如果throw java.text.ParseException或者NullPointerException，就说明格式不对
			convertSuccess = false;
		}
		return convertSuccess;
	}

	/**
	 *
	 * 功能描述:获取当前的时间，时间格式由入参指定时间格式
	 * @return 当天0点时间
	 * @throws ParseException
	 *
	 */
	public static Date getCurrentTime()  {
		Calendar cal = Calendar.getInstance();
        cal.setTime(new Date());
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.SECOND,0);
        cal.set(Calendar.MINUTE,0);
        Date date=cal.getTime();
		return date;
	}

	 /**
     * 功能描述：获取两个日期的时间间隔，单位是小时，保留一位小数
     * @param startDay 开始时间
     * @param endDay 结束时间
     * @param dateFormatStr 格式化
     * @return
     */
    public static BigDecimal getBetweenDoubleMinute(String startDay, String endDay, String dateFormatStr) throws ParseException {
    	if (startDay == null || endDay == null || dateFormatStr == null) {
			throw new IllegalArgumentException(
					"startDay or endDay or dateFormat should not be null");
		}

    	DateFormat dateFormat = new SimpleDateFormat(dateFormatStr);
    	long diff = dateFormat.parse(endDay).getTime() - dateFormat.parse(startDay).getTime();
    	BigDecimal diffBigDeciml = new BigDecimal(diff);
    	BigDecimal minBigDeciml = new BigDecimal(1000 * 60);
    	BigDecimal betweenMinute = diffBigDeciml.divide(minBigDeciml, 0, BigDecimal.ROUND_CEILING);
    	return betweenMinute;
    }

    /**
     *
     * 功能描述：
     * @param configAppointTimeStr
     * @return
     * @throws ParseException
     */
    public static String getAppendOneDayTime(String configAppointTimeStr)
    		throws ParseException{
    	Date appointTime = DateUtils.
				parseToFormatDate(configAppointTimeStr, DateUtils.SIMPLE_DATE_STR);
		Date appendAppointTime = DateUtils.addDate(appointTime, 1);
		SimpleDateFormat ds = new SimpleDateFormat(DateUtils.SIMPLE_DATE_STR);
        return ds.format(appendAppointTime.getTime());
    }

    /**
     *
     * 功能描述：获取n天后的时间（格式由传入formatStr决定）
     * @param formatStr 转换时间格式 days 增减天数  changeType变更类型（是增加还是减时间）
     * @return
     * @throws
     */
    public static String getAfterDaysTime(String formatStr,int Days){
    	 Calendar calendar = Calendar.getInstance();
		 SimpleDateFormat sdf = new SimpleDateFormat(formatStr);
		 calendar.add(Calendar.DAY_OF_YEAR, Days);
		 Date date = calendar.getTime();
		 String nextDay=sdf.format(date);
		 return nextDay;
    }


    /**
	 *
	 * 功能描述：获取指定日历的前或后几个月的日期
	 * @param date
	 * @param beforeOrAfterMonth
	 * @param formatStr
	 * @return
	 */
	public static String getCalendarDate(Date date,int beforeOrAfterMonth,String formatStr){
		SimpleDateFormat sdf = new SimpleDateFormat(formatStr);
		Calendar calendar=Calendar.getInstance();
		calendar.setTime(new Date());
		calendar.add(Calendar.DATE, beforeOrAfterMonth);//指定前后的几个月
		date = calendar.getTime();
		return sdf.format(date);
	}

	/**
	 *
	 * 功能描述：获取当前日期格式为   yyyy-MM-dd HH:mm:ss
	 * @return
	 */
	 public static String getCurDatetimeStr()
	  {
	    return getDateTimeFmtter().format(new Date());
	  }
	 private static SimpleDateFormat getDateTimeFmtter()
	  {
	    return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	  }

    /**
     * 功能描述：获取当前日期格式为 yyyy-MM-dd
     * @return
     */
    public static String getCurDateYMDStr() {
        return getDateTimeFmtters().format(new Date());
    }
    private static SimpleDateFormat getDateTimeFmtters() {
        return new SimpleDateFormat(SIMPLE_DATE_STR);
    }
    /**
     * 功能描述：在指定日期上面增加天数，返回增加后的日期
     * @return
     */
    public static String getDateYMDPlusDay(Integer num,String newDate) throws ParseException{
        SimpleDateFormat format = new SimpleDateFormat(PART_DATE_STR);
        Date  currdate = format.parse(newDate);
        Calendar ca = Calendar.getInstance();
        ca.add(Calendar.DATE, num);
        currdate = ca.getTime();
         String enddate = format.format(currdate);
        return enddate;
    }
	 /**
		 * 
		 * 功能描述:日期字符串类型转换字符串
		 * @param dateStr
		 * @param formatStr
		 * @return
		 * @throws ParseException
		 */
		public static String stringParseToFormatString(String dateStr, String formatStr) throws ParseException {
			SimpleDateFormat sdf = new SimpleDateFormat(SIMPLE_DATE_STR);
	         Date date =sdf.parse(dateStr);
	         dateStr= sdf.format(date);
			return dateStr;
		}
		
		/**
		 * 
		 * 功能描述：根据日期计算年龄。
		 * @param birthdayDate
		 * @param targetDate
		 * @return
		 */
		public static int calcAgeByDate(Date birthdayDate,Date targetDate){
			Calendar birthdayCal = Calendar.getInstance();
			Calendar targetCal = Calendar.getInstance();
			Calendar temp = null;
			birthdayCal.setTime(birthdayDate);
			targetCal.setTime(targetDate);
			
			if (targetCal.before(birthdayCal)){
				temp = targetCal;
				targetCal = birthdayCal;
				birthdayCal = temp;
			}

			int yearNow = targetCal.get(Calendar.YEAR);
			int monthNow = targetCal.get(Calendar.MONTH) + 1;
			int dayOfMonthNow = targetCal.get(Calendar.DAY_OF_MONTH);

			int yearBirth = birthdayCal.get(Calendar.YEAR);
			int monthBirth = birthdayCal.get(Calendar.MONTH) + 1;
			int dayOfMonthBirth = birthdayCal.get(Calendar.DAY_OF_MONTH);

			int age = yearNow - yearBirth;

			if (monthNow <= monthBirth) {
				if (monthNow == monthBirth) {
					if (dayOfMonthNow < dayOfMonthBirth) {
						age--;
					}
				} else {
					age--;
				}
			}
			return age;
		}
	  
		/**
		 * 功能描述：将yyyyMMddhhmmss格式的日期字符串转换为yyyy-MM-dd HH:mm:ss格式的日期字符串<br>
		 * @param orgDateStr
		 * @return
		 */
		public static String stringDateToFormatString(String orgDateStr) throws ParseException {
			Date date = (Date) new SimpleDateFormat(DATE_FORMAT_YYYYMMDDHHMMSS).parse(orgDateStr);
			return new SimpleDateFormat(FULL_DATE_STR).format(date);
		}
		
		/**
		 * 功能描述：时间比较(只支持时分秒比较)，时间格式 HH:MM:SS
		 * @param time1
		 * @param time2
		 * @return
		 */
		public static boolean compTime(String time1,String time2) throws NumberFormatException{  		
            String[]array1 = time1.split(":");  
            int total1 = Integer.valueOf(array1[0])*3600+Integer.valueOf(array1[1])*60+Integer.valueOf(array1[2]);  
            String[]array2 = time2.split(":");  
            int total2 = Integer.valueOf(array2[0])*3600+Integer.valueOf(array2[1])*60+Integer.valueOf(array2[2]);  
            return total1-total2>0?true:false;  	  
	    }  


		/**
		 * 功能描述：将yyyyMMddhhmm格式的日期字符串转换为yyyy-MM-dd HH:mm格式的日期字符串<br>
		 * @param orgDateStr
		 * @return
		 */
		public static String dateStringToFormatString(String orgDateStr) throws ParseException {
			Date date = (Date) new SimpleDateFormat(DATE_FORMAT_YYYYMMDDHHMM).parse(orgDateStr);
			return new SimpleDateFormat(PART_DATE_STR).format(date);
		}
		
}
